package com.link2room.aeriabots.controller.inside;

import com.link2room.aeriabots.dto.param.inside.WxQrcodeInsideParamDto;
import com.link2room.aeriabots.dto.result.base.WxQrcodeResDto;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.aeriabots.facade.IQRCodeFacadeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by LN on 2016/10/10.
 */
@Api(tags = {"微信二维码"})
@RestController
@RequestMapping("/in/WxQrcode")
public class WxQrCodeInsideController {
    @Resource
    private IQRCodeFacadeService qrcodeFacadeService;

    @ApiOperation(value = "微信二维码生成", response = WxQrcodeResDto.class)
    @ApiImplicitParams(value = {
    })
    @RequestMapping(method = RequestMethod.POST)
    public BaseResultDto createWxQrCode(
            @RequestBody WxQrcodeInsideParamDto paramDto
    ) throws Exception {
        BaseResultDto resDto = new BaseResultDto();
        WxQrcodeResDto res = qrcodeFacadeService.wxCreateQrcode(paramDto);
        resDto.setResultCode(0);
        resDto.setResultInfo(res);
        return resDto;
    }

    @ApiOperation(value = "微信二维码获取", response = WxQrcodeResDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "type", value = "类型", required = true, paramType = "query"),
            @ApiImplicitParam(name = "key", value = "唯一编号", required = true, paramType = "query"),
    })
    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto getWxQrCode(
            @RequestParam(name = "type") String type,
            @RequestParam(name = "key") String key
    ) throws Exception {
        BaseResultDto resDto = new BaseResultDto();
        WxQrcodeInsideParamDto paramDto = new WxQrcodeInsideParamDto();
        paramDto.setType(type);
        paramDto.setKey(key);
        WxQrcodeResDto res = qrcodeFacadeService.getQrcode(paramDto);
        resDto.setResultCode(0);
        resDto.setResultInfo(res);
        return resDto;
    }
}
